package com.example.petplatform.service;

import com.example.petplatform.dao.PetTypesDao;
import com.example.petplatform.entity.PetTypes;
import com.example.petplatform.entity.Param.Params;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetTypesService {
    @Resource
    private PetTypesDao petTypesDao;

    public List<PetTypes> getAllTypes() {
        return petTypesDao.getAllTypes();
    }

    public PageInfo<PetTypes> getSearch(Params params) {
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        List<PetTypes> list = petTypesDao.getSearch(params);
        return PageInfo.of(list);
    }

    public List<PetTypes> addType(PetTypes petType) {
        petTypesDao.insertSelective(petType);
        return petTypesDao.getAllTypes();
    }

    public List<PetTypes> updateType(PetTypes petType) {
        petTypesDao.updateByPrimaryKeySelective(petType);
        return petTypesDao.getAllTypes();
    }

    public List<PetTypes> deleteType(Integer id) {
        petTypesDao.deleteByPrimaryKey(id);
        return petTypesDao.getAllTypes();
    }
}
